package view.pieces;

import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.Observer;

import resources.GlobalSettings;

import model.pieces.Piece;

public abstract class PieceDisplayView implements Observer {
	protected Graphics2D g2D;
	protected final Piece piece;
	protected Piece oldPiece;

	public PieceDisplayView(Graphics2D g2D, Piece piece) {
		this.g2D = g2D;
		this.piece = piece;
		this.oldPiece = null;

		// estrategia de pintado descentralizado
		this.piece.addObserver(this);
	}

	public abstract void paint(Graphics2D g2D);

	protected void clearOldPiece() {
		this.g2D.clearRect(this.oldPiece.getCol() * GlobalSettings.pieceWidth,
				this.oldPiece.getRow() * GlobalSettings.pieceHeight,
				GlobalSettings.pieceWidth,
				GlobalSettings.pieceHeight);
	}
	
	protected Rectangle2D getPieceRectangle() {
		return new Rectangle2D.Double(
				this.piece.getCol() * GlobalSettings.pieceWidth,
				this.piece.getRow() * GlobalSettings.pieceHeight,
				GlobalSettings.pieceWidth,
				GlobalSettings.pieceHeight);
	}
}
